package com.qifenqian.turbot.module.ui.restaurant

import android.content.Context
import android.view.View
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseFragment
import com.qifenqian.turbot.module.contract.RestaurantContract
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantEntity
import com.qifenqian.turbot.module.presenter.RestaurantPresenter
import com.qifenqian.turbot.module.ui.comment.CustomerCommentActivity
import com.qifenqian.turbot.module.ui.staff.StaffManageActivity
import com.qifenqian.turbot.module.ui.dish.ACTION_MANAGE
import com.qifenqian.turbot.module.ui.dish.DishManageActivity
import com.qifenqian.turbot.module.ui.setting.SettingActivity
import kotlinx.android.synthetic.main.fragment_restaurant.view.*

/**
 * @author H
 * @createDate 2018/12/19 13:35
 * @description 餐厅Fragment
 * @see
 * @since
 */
class RestaurantFragment : BaseFragment<RestaurantPresenter, RestaurantContract.View>(), RestaurantContract.View {

    override fun getRestaurantInfoResult(isSuccess: Boolean, code: Int, msg: String?, restaurantEntity: RestaurantEntity?) {
        if (isSuccess) {
            mView.tv_restaurant_name.text = restaurantEntity!!.shortName
            mView.tv_restaurant_address.text = restaurantEntity.province + restaurantEntity.city + restaurantEntity.area + restaurantEntity.address
//        Glide.with(this).load(restaurantEntity.imageUrl).into(mView.iv_restaurant_image)
        } else {
            mView.tv_restaurant_name.text = "店名"
            mView.tv_restaurant_address.text = "地址"
            mView.iv_restaurant_image.setImageResource(R.mipmap.ic_launcher_round)
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.fragment_restaurant
    }

    override fun bindPresenter(): RestaurantPresenter {
        return RestaurantPresenter(activity as Context, this)
    }

    override fun initial(view: View) {
        view.ly_restaurant_manage.setOnClickListener {
            RestaurantManageActivity.startThis(activity as Context)
        }
        view.ly_restaurant_dishes.setOnClickListener {
            DishManageActivity.startThis(activity as Context, ACTION_MANAGE)
        }
        view.ly_restaurant_customer_comment.setOnClickListener {
            CustomerCommentActivity.startThis(activity as Context)
        }
        view.ly_restaurant_staff_manage.setOnClickListener {
            StaffManageActivity.startThis(activity as Context)
        }
        view.ly_restaurant_setting.setOnClickListener {
            SettingActivity.startThis(activity as Context)
        }
    }

    override fun onResume() {
        super.onResume()
        // TODO: 2018/12/25 16:50 登录成功之后要把相关的信息保存在sp中,如restaurantId ----->
        mPresenter!!.getRestaurantInfo(false)
    }
}
